﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZenInterface
{
    public partial class temporalGraphClass : Form
    {

        Properties.Settings settings;

        public temporalGraphClass(Properties.Settings inSettings)
        {
            InitializeComponent();


            settings = inSettings;
            Random random = new Random();

            chart.ChartAreas[0].AxisX.Maximum = settings.applicationDataBufferSize;

            int i = chart.Series[0].Points.Count;

            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[0].Points.AddXY(i, 0);
            }
            i = chart.Series[1].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[1].Points.AddXY(i, 0);
            }
            i = chart.Series[2].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[2].Points.AddXY(i, 0);
            }
            i = chart.Series[3].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[3].Points.AddXY(i, 0);
            }

            for (int j = 0; j < chart.ChartAreas.Count; j++)
            {
                chart.ChartAreas[j].AxisX.Maximum = settings.applicationDataBufferSize;
            }
            
        }

        public void update(DataTable inDataTable)
        {
            DataRow dataRow;
            for (int i = 0; i < inDataTable.Rows.Count; i++)
            {
                dataRow = inDataTable.Rows[i];
                chart.Series[0].Points[i].SetValueXY(i, dataRow[0]);
                chart.Series[1].Points[i].SetValueXY(i, dataRow[1]);
                chart.Series[2].Points[i].SetValueXY(i, dataRow[2]);
                chart.Series[3].Points[i].SetValueXY(i, dataRow[3]);
                //chart.Series[0].Points[i].XValue = (double)dataRow[0];
                //dataRow = dataSet.Tables[0].Rows[i];
                
                //dataRow[0] = inDataTable.Rows[i].ItemArray[0];
                //dataRow[1] = inDataTable.Rows[i].ItemArray[1];
                //dataRow[2] = inDataTable.Rows[i].ItemArray[2];
                //dataRow[3] = inDataTable.Rows[i].ItemArray[3];
            }
            chart.Invalidate();
        }

        private void temporalGraphClass_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                this.Hide();
            }
        }
    }
}
